<template>
  <div>
    <div>
      文本：<input type="text" v-model="realContext">  <br>
      复制文本：<h2>{{realContext}}</h2>
    </div>

  </div>
</template>
<script>
  import {ref,customRef} from "vue";

  export default {
    name: "Test",
    setup() {
      let context = ''

       function myRef(value){
        var timer
        return customRef((track,trigger)=>{
          return{
            get(){
              track()
              return value
            },
            set(newValue){
              clearTimeout(timer)
              timer = setTimeout(()=>{
                value = newValue
                trigger()
              },500)
              
            }
          }
        })
      }


      let realContext = myRef(context)

      return {
        realContext
      }
    }
  };
</script>
<style>
</style>